﻿@model IList<LogEntity>
@{
}

<div class="cl pd-5 bg-1 bk-gray">
	<span class="l">
		<span class="select-box inline">
			<select id="dropSearchName" class="select">
				<option value="Title">标题</option>
				<option value="UserName">操作人</option>
				<option value="UserIP">IP地址</option>
			</select>
		</span>
		<input type="text" class="input-text" style="width:250px" id="txtSearchKeyword" onkeypress="javascript:return DefaultButton(event, 'btnSearch')">
		<button id="btnSearch" type="button" class="btn btn-success" onclick="loadTables(0,10);"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
		<a href="javascript:;" onclick="DeleteMulti('/Admin/SiteConfig/DelLogMulti',loadTables)" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
		<a href="javascript:;" onclick="DelLogAll()" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe6e2;</i> 清空日志</a>
	</span>
	<span class="r">共有数据：<strong id="ctlRecordTotal">0</strong> 条</span>
</div>
<div class="cl pd-5 bg-1 bk-gray mt-20">
	<div class="tabBar cl">
		<span onclick="GoToTab(this,-1);" class="current">全部</span>
		<span onclick="GoToTab(this,0);">常规记录</span>
		<span onclick="GoToTab(this,1);">登录成功</span>
		<span onclick="GoToTab(this,2);">登录失败</span>
		<span onclick="GoToTab(this,3);">退出登录</span>
		<span onclick="GoToTab(this,4);">越权操作</span>
		<span onclick="GoToTab(this,5);">异常记录</span>
		<span onclick="GoToTab(this,6);">管理错误</span>
		<span onclick="GoToTab(this,7);">重大行为</span>
		<span onclick="GoToTab(this,8);">系统行为</span>
	</div>
	<input type="hidden" id="hidTab" value="-1" />
</div>
<table class="table table-border table-bordered table-bg table-hover">
	<thead>
		<tr class="text-c">
			<th width="25"><input type="checkbox" name="" value=""></th>
			<th width="150">标题</th>
			<th width="70">类型</th>
			<th width="150">访问地址</th>
			<th width="150">操作时间</th>
			<th width="100">IP地址</th>
			<th width="100">操作人</th>
			<th width="50">查看</th>
		</tr>
	</thead>
	<tbody id="tableBody"></tbody>
</table>
<div style="text-align:right;">
	<ul id="grid_paging_part"></ul>
</div>
<div class="cl pd-5 bg-1 bk-gray">
	<span class="l">
		<strong>删除</strong>
		<span class="select-box inline">
			<select id="dropOffSet" class="select">
				<option value="0">请选择你要进行的操作</option>
				<option value="-7">一个星期前的</option>
				<option value="-15">半个月前的</option>
				<option value="-30">一个月前的</option>
				<option value="1">最后一万条</option>
				<option value="10">最后十万条</option>
			</select>
			<select id="dropLogCategory" class="select">
				<option value="-1">所有类型</option>
				<option value="0">常规类型</option>
				<option value="1">登录成功</option>
				<option value="2">登录失败</option>
				<option value="3">登录退出</option>
				<option value="4">越权操作</option>
				<option value="5">异常记录</option>
				<option value="6">管理错误</option>
				<option value="7">重大行为</option>
				<option value="8">系统行为</option>
			</select>
		</span>
		<strong>日志</strong>
		<a href="javascript:;" onclick="OffSetDel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 执行选定的操作</a>
	</span>
</div>
@Html.AntiForgeryToken()
@section scripts {
	<script type="text/javascript">
		$(function () {
			loadTables(0, 10);
		});
		function loadTables(PageNum, PageSize) {
			$("#tableBody").html("");
			var SearchName = $("#dropSearchName").val();
			var SearchKeyword = $("#txtSearchKeyword").val();
			var TabStatus = $("#hidTab").val();
			var parm = "PageNum=" + PageNum + "&PageSize=" + PageSize
				+ "&SearchName=" + encodeURIComponent(SearchName)
				+ "&SearchKeyword=" + encodeURIComponent(SearchKeyword)
				+ "&TabStatus=" + encodeURIComponent(TabStatus);
			$.ajax({
				type: "GET",
				url: "/Admin/SiteConfig/GetLogManager?" + parm + "&_t=" + new Date().getTime(),
				contentType: "application/x-www-form-urlencoded;charset=UTF-8",
				success: function (data) {
					$.each(data.rowList, function (i, item) {
						var categoryTitle = "未分类";
						switch (item.category) {
							case 0:
								categoryTitle = "常规记录";
								break;
							case 1:
								categoryTitle = "登录成功";
								break;
							case 2:
								categoryTitle = "登录失败";
								break;
							case 3:
								categoryTitle = "退出登录";
								break;
							case 4:
								categoryTitle = "越权操作";
								break;
							case 5:
								categoryTitle = "异常记录";
								break;
							case 6:
								categoryTitle = "管理错误";
								break;
							case 7:
								categoryTitle = "重大行为";
								break;
							case 8:
								categoryTitle = "系统行为";
								break;
						}
						var tr = "<tr class=\"text-c\">";
						tr += "<td><input type='checkbox' value='" + item.logID + "' class='checkboxs'></td>";
						tr += "<td>" + item.title + "</td>";
						tr += "<td>" + categoryTitle + "</td>";
						tr += "<td>" + item.scriptName + "</td>";
						tr += "<td>" + (item.timestamp == null ? "" : (formatDateTime(item.timestamp) == "9999-12-31 23:59:59") ? "" : formatDateTime(item.timestamp)) + "</td>";
						tr += "<td>" + item.userIP + "</td>";
						tr += "<td>" + item.userName + "</td>";
						tr += "<td class=\"td-manage\">";
						tr += "<a title=\"详细\" href=\"javascript:;\" style=\"text-decoration:none\" onclick=\"layer_show('查看日志','/Admin/SiteConfig/ViewLog?id=" + item.logID + "')\" class=\"ml-5\"><i class=\"Hui-iconfont\">&#xe665;</i></a>";
						tr += "</td>";
						tr += "</tr>";
						$("#tableBody").append(tr);
					})
					$("#ctlRecordTotal").html(data.recordTotal);
					var elment = $("#grid_paging_part"); //分页插件的容器id
					if (data.recordTotal > 0) {
						var options = { //分页插件配置项
							bootstrapMajorVersion: 3,
							currentPage: data.pageNum + 1, //当前页
							numberOfPages: data.recordTotal, //总数
							totalPages: data.pageCount, //总页数
							itemTexts: function (type, page, current) {
								switch (type) {
									case "first":
										return "首页";
									case "prev":
										return "上一页";
									case "next":
										return "下一页";
									case "last":
										return "末页";
									case "page":
										return page;
								}
							},
							onPageChanged: function (event, oldPage, newPage) { //页面切换事件
								loadTables(newPage - 1, PageSize);
							}
						}
						elment.bootstrapPaginator(options); //分页插件初始化
					}
				},
				error: function (data, status, e) {
					alert('得到数据失败!');
				}
			})
		}
		function OffSetDel() {
			var OffSet = $("#dropOffSet").val();
			var LogCategory = $("#dropLogCategory").val();
			if (OffSet == "0") {
				layer.alert('请选择你要进行的操作!');
				return;
			}
			//询问框
			layer.confirm("您确认删除选定的记录吗？", {
				btn: ["确定", "取消"]
			}, function () {
				var sendData = { "OffSet": OffSet, "LogCategory": LogCategory };
				var url = "/Admin/SiteConfig/OffSetDelLog";
				$.ajax({
					type: "Post",
					url: url,
					data: sendData,
					headers: {
						"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
					},
					error: function (data, status, e) {
						layer.alert('操作失败!');
					},
					success: function (data) {
						if (data.result == "ok") {
							layer.alert('操作成功!');
							loadTables(0, 10);
						}
						else {
							layer.alert(data.result);
						}
					}
				});
			});
		}
		function DelLogAll() {
			//询问框
			layer.confirm("您确认删除选定的记录吗？", {
				btn: ["确定", "取消"]
			}, function () {
				var url = "/Admin/SiteConfig/DelLogAll";
				$.ajax({
					type: "Post",
					url: url,
					data: null,
					headers: {
						"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
					},
					error: function (data, status, e) {
						layer.alert('操作失败!');
					},
					success: function (data) {
						if (data.result == "ok") {
							layer.alert('操作成功!');
							loadTables(0, 10);
						}
						else {
							layer.alert(data.result);
						}
					}
				});
			});
		}
	</script>
}